package com.ste.server;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.logging.Logger;

import com.ste.domain.Client;

public class WriteClient implements Runnable {

	private OutputStream os;
	private Client client;
	private static Logger log = Logger.getLogger(WriteClient.class.getName());

	public WriteClient(OutputStream os, Client client) {
		this.client = client;
		this.os = os;
	}

	@Override
	public void run() {
		PrintWriter oos = null;
		try {
			oos = new PrintWriter(os, true);
			oos.flush();
			String mes = null;
			while (true) {
				mes = client.getSendQueue().take();
				oos.println(mes);
				log.info(mes);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			if (oos != null)
				oos.close();
		}
	}

}
